package handler;

import my.netty.channel.handler.AbstractChannelHandlerContext;
import my.netty.channel.handler.SimpleChannelInboundHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.ByteBuffer;

public class PrintStringHandler extends SimpleChannelInboundHandler {
    private static final Logger log = LoggerFactory.getLogger(PrintStringHandler.class);
    @Override
    protected <I> void channelRead0(AbstractChannelHandlerContext ctx, I msg) {
        if (msg instanceof ByteBuffer) {
            ByteBuffer buff = (ByteBuffer) msg;
            byte[] bytes = new byte[buff.position()];
            buff.flip();
            buff.get(bytes);
            log.info("接受到消息[{}]", new String(bytes));
        }
    }
}
